<template>
  <!-- 登录 -->
  <view class="content box">
    <view class="box_images">
      <image src="../../static/images/bg_dengluzhuce.png" mode=""></image>
    </view>
    <view class="box_title">
      <view class="boxt">忘记密码</view>
      <view class="boxc">请在下方验证信息重新设置密码</view>
    </view>

    <view class="box_inp">
      <!-- 手机号码输入 -->
      <u-input
        class="input"
        placeholder="请输入手机号码"
        maxlength="20"
        border="none"
        shape="circle"
        color="#888888"
        :fontSize="inputFont"
        v-model="mobile"
        @change="changeMobile"
        placeholderStyle="color:#888888;padding-left:50rpx"
      ></u-input>
      <!-- 验证码输入 -->
      <u-input
        class="inputPassword"
        type="number"
        placeholder="请输入验证码"
        maxlength="6"
        border="none"
        shape="circle"
        color="#888888"
        :fontSize="inputFont"
        v-model="smsCode"
        @change="changeSmsCode"
        placeholderStyle="color:#888888;padding-left:50rpx"
      >
        <template slot="suffix">
          <u-code
            ref="uCode"
            @change="codeChange"
            seconds="120"
            changeText="Xs"
          ></u-code>
          <view @tap="getCode" class="codeTip">{{ tips }}</view>
        </template>
      </u-input>

      <!-- 密码输入 -->
      <u-input
        class="inputPassword"
        type="password"
        placeholder="请输入6~12位字母、数字混合密码"
        maxlength="20"
        border="none"
        shape="circle"
        color="#888888"
        :fontSize="inputFont"
        v-model="password"
        @change="changePassword"
        placeholderStyle="color:#888888;padding-left:50rpx"
      ></u-input>
      <!-- 密码再次确认 -->
      <u-input
        class="inputPassword"
        type="password"
        placeholder="请再次确认登录密码"
        maxlength="20"
        border="none"
        shape="circle"
        color="#888888"
        :fontSize="inputFont"
        v-model="password_two"
        @change="changePassword_two"
        placeholderStyle="color:#888888;padding-left:50rpx"
      ></u-input>
      <view class="login" @click="updatePwd">
        <view class="loginFont">保存</view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      mobile: "",
      smsCode: "",
      password: "",
      password_two: "",
      inputFont: "30rpx",
      isPassword: false,
      tips: "",
      checked: [],
    };
  },
  methods: {
    changeMobile() {
      console.log(this.mobile);
    },
    changeSmsCode() {
      console.log(this.smsCode);
    },
    changePassword() {
      console.log(this.password);
    },
    changePassword_two() {
      console.log(this.password_two);
    },
    codeChange(text) {
      this.tips = text;
    },
    updatePwd() {
      this.$http
        .passportUpdatePassword({
          mobile: this.mobile,
          password: this.password,
          password_two: this.password_two,
          smsCode: this.smsCode,
        })
        .then((res) => {
          console.log(res, "修改密码");
          uni.$u.toast(res.message);
          setTimeout(() => {
            uni.redirectTo({
              url: "/pages/login/index",
            });
            this.$refs.uCode.start();
          }, 2000);
        })
        .catch((error) => {
          console.log(error);
          uni.$u.toast(error);
        });
    },
    getCode() {
      if (!this.mobile) {
        return uni.$u.toast("请输入手机号");
      }
      if (this.$refs.uCode.canGetCode) {
        this.$http
          .sendSmsCaptcha({ mobile: this.mobile })
          .then((res) => {
            // 模拟向后端请求验证码
            uni.showLoading({
              title: "正在获取验证码",
            });
            setTimeout(() => {
              uni.hideLoading();
              // 这里此提示会被this.start()方法中的提示覆盖
              uni.$u.toast("验证码已发送");
              // 通知验证码组件内部开始倒计时
              this.$refs.uCode.start();
            }, 2000);
          })
          .catch((error) => {
            console.log(error);
            uni.$u.toast(error);
          });
      } else {
        uni.$u.toast("倒计时结束后再发送");
      }
    },
    login() {
      uni.navigateTo({
        url: "index",
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.box {
  background: #111111;
  padding: 212rpx 60rpx 0;
  box-sizing: border-box;
  // overflow-y: scroll;
}
.box_images {
  width: 370rpx;
  height: 266rpx;
  position: fixed;
  right: 0;
  top: 0;
  image {
    width: 100%;
    height: 100%;
  }
}
.box_title {
  .boxt {
    font-size: 56rpx;
    font-family: PingFang SC-Bold, PingFang SC;
    font-weight: bold;
    color: #fff;
  }
  .boxc {
    font-size: 30rpx;
    font-family: PingFang SC-Medium, PingFang SC;
    font-weight: bold;
    color: #a2a2a2;
    margin-top: 12rpx;
  }
}
.box_inp {
  width: 100%;

  .input {
    background-color: #272c29;
    width: 630rpx;
    height: 96rpx;
    margin-top: 112rpx;
  }
  .inputPassword {
    width: 630rpx;
    height: 96rpx;
    background-color: #272c29;
    margin-top: 40rpx;
    position: relative;

    .codeTip {
      position: absolute;
      right: 50rpx;
      bottom: 26rpx;
      font-size: 30rpx;
      font-weight: 400;
      color: #55b877;
    }
  }
  /deep/.uni-input-input {
    left: 50rpx;
  }
  .verify {
    margin: 16rpx 0 0 30rpx;
    font-size: 24rpx;
    font-family: PingFang SC-Medium, PingFang SC;
    font-weight: 400;
    color: #ee6060;
  }

  .inputBottom {
    margin-top: 32rpx;
    display: flex;
    justify-content: space-between;
    padding: 0 30rpx;

    .forgotPassw {
      font-size: 28rpx;
      font-weight: 400;
      color: #adadad;
    }
    .verCodeLogin {
      font-size: 28rpx;
      font-weight: 400;
      color: #55b877;
    }
  }

  .login {
    width: 630rpx;
    height: 96rpx;
    margin-top: 54rpx;
    background: linear-gradient(360deg, #50b674 0%, #aeddbd 100%);
    border-radius: 48rpx 48rpx 48rpx 48rpx;

    .loginFont {
      line-height: 96rpx;
      text-align: center;
      font-size: 30rpx;
      font-weight: 400;
      color: #ffffff;
    }
  }

  .account {
    text-align: center;
    margin-top: 32rpx;
    font-size: 28rpx;
    padding-bottom: 100rpx;

    .noAccount {
      color: #d8d8d8;
    }
    .registerAccount {
      color: #55b877;
    }
  }
}
.box_bottom {
  position: fixed;
  bottom: 40rpx;
  display: flex;
  font-size: 26rpx;
  color: #888888;
  .user {
    color: #55b877;
  }
}

// text:first-child
</style>